package com.neusoft.yiyang.medical.controller;

import com.neusoft.yiyang.common.entity.medical.MedicalRecord;
import com.neusoft.yiyang.medical.service.MedicalRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "病历管理接口", description = "负责客户病历的创建、查询、更新及删除，记录客户健康状况和诊疗历史")
@RestController
@RequestMapping("/medical-records")
public class MedicalRecordController {

    @Autowired
    private MedicalRecordService medicalRecordService;

    @Operation(summary = "创建病历", description = "为客户新增病历记录（含主诉、现病史、诊断结果等医疗信息）")
    @PostMapping("/create")
    public void createMedicalRecord(
            @Parameter(description = "病历信息（含客户ID、就诊时间、诊断内容等）", required = true)
            @RequestBody MedicalRecord medicalRecord) {
        medicalRecordService.createMedicalRecord(medicalRecord);
    }

    @Operation(summary = "获取所有病历", description = "查询系统中所有客户的病历记录")
    @GetMapping("/all")
    public List<MedicalRecord> getAllMedicalRecords() {
        return medicalRecordService.getAllMedicalRecords();
    }

    @Operation(summary = "查询客户的病历", description = "获取指定客户的所有病历记录（按时间排序）")
    @GetMapping("/customer/{customerId}")
    public List<MedicalRecord> getMedicalRecordsByCustomerId(
            @Parameter(description = "客户ID", required = true)
            @PathVariable Integer customerId) {
        return medicalRecordService.getMedicalRecordsByCustomerId(customerId);
    }

    @Operation(summary = "更新病历", description = "修改病历内容（如补充诊断、更新治疗方案等）")
    @PutMapping("/update/{medicalRecordId}")
    public void updateMedicalRecord(
            @Parameter(description = "病历ID", required = true) @PathVariable Integer medicalRecordId,
            @Parameter(description = "更新后的病历信息", required = true) @RequestBody MedicalRecord medicalRecord) {
        medicalRecord.setMedicalRecordId(medicalRecordId);
        medicalRecordService.updateMedicalRecord(medicalRecord);
    }

    @Operation(summary = "删除病历", description = "移除指定的病历记录（谨慎操作，建议保留历史医疗数据）")
    @DeleteMapping("/delete/{medicalRecordId}")
    public void deleteMedicalRecord(
            @Parameter(description = "病历ID", required = true) @PathVariable Integer medicalRecordId) {
        medicalRecordService.deleteMedicalRecord(medicalRecordId);
    }
}